//
//  FactionUI.m
//  PacketKithen
//
//  Created by 张文超 on 16/3/7.
//  Copyright © 2016年 张文超. All rights reserved.
//

#import "FactionUI.h"

@implementation FactionUI

//定制view
+ (UIView *)createView:(CGRect)frame backColor:(UIColor *)color{
    UIView * view = [[UIView alloc]initWithFrame:frame];
    view.backgroundColor = color;
    return view;

}

//定制button
+ (UIButton *)createButton:(CGRect)frame title:(NSString *)title titleColor:(UIColor *)color imageName:(NSString *)imageName backImageName:(NSString *)backImageName target:(id)target action:(SEL)action{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = frame;
    //button字体设置
    if (title) {
        [button setTitle:title forState:UIControlStateNormal];
        [button setTitleColor:color forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    if (imageName) {
        [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    if (backImageName) {
        [button setBackgroundImage:[UIImage imageNamed:backImageName] forState:UIControlStateNormal];
    }
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return button;
}

//定制label
+ (UILabel *)createLabel:(CGRect)frame title:(NSString *)title titleColor:(UIColor *)titleColor fontSize:(CGFloat)fontSize{
    UILabel * label = [[UILabel alloc]initWithFrame:frame];
    label.textAlignment = NSTextAlignmentCenter;
    if (title) {
        label.text = title;
        label.textColor = titleColor;
        label.font = [UIFont systemFontOfSize:fontSize];
        
    }
    return label;
}


//定制imageView

+ (UIImageView *)createImageView:(CGRect)frame imageName:(NSString *)imageName{
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:frame];
    imageView.image =[UIImage imageNamed:imageName];
    return imageView;
}

//定制 textField
+ (UITextField *)createTextField:(CGRect)frame placeHoder:(NSString *)placeHoder{
    UITextField * field = [[UITextField alloc]initWithFrame:frame];
    field.placeholder = placeHoder;
    field.font = [UIFont systemFontOfSize:15];
    field.textAlignment = NSTextAlignmentCenter;
    return field;
}

+(UIImage *)getImageWithColor:(UIColor *)color{
    
    CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, 64);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}


@end
